package com.tanhua.server;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.junit.Test;

public class Demo02 {
    @Test
    public void testCreateToken() {
        String token= Jwts.builder()
                .claim("id",1)
                .claim("mobile","13011322613")
                .signWith(SignatureAlgorithm.HS256, "itheima")
                .compact();
        System.out.println(token);
        //eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwibW9iaWxlIjoiMTMwMTEzMjI2MTMifQ.EFexyLVItCbP2h7ZpvoEWNdUTduCE5MLSz6GJhHhZ1w
    }
    @Test
    public void testEqToken() {
        String token="eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwibW9iaWxlIjoiMTMwMTEzMjI2MTMifQ.EFexyLVItCbP2h7ZpvoEWNdUTduCE5MLSz6GJhHhZ1w";
        Jws<Claims> jws = Jwts.parser().setSigningKey("itheima").parseClaimsJws(token);
        System.out.println(jws.getHeader());
        System.out.println(jws.getBody());
        System.out.println(jws.getSignature());


    }
}
